
#include "HttpCmdGetDateTime.h"
#include "SysInfo.h"

CHttpCmdGetDateTime::CHttpCmdGetDateTime()
{ 
    ClearCmdLocalData();
}

CHttpCmdGetDateTime::~CHttpCmdGetDateTime()
{

}

bool CHttpCmdGetDateTime::CheckParamVaild(const std::string &strReqMessage)
{
    if(strReqMessage.empty())
    {
        return true;
    }

    return ParseParamDataToSave(strReqMessage);
}

bool CHttpCmdGetDateTime::FillRspData(std::string &strRspData)
{
    // need some system helper functions
    neb::CJsonObject rspJsonObj;
    rspJsonObj.AddEmptySubObject("Data");
    neb::CJsonObject &dataJsonObj = rspJsonObj["Data"];

    std::string strTmpValue;
    CSysInfo::GetSystemTime(strTmpValue);
    dataJsonObj.Add("SysTime", strTmpValue);


    CSysInfo::GetSystemDate(strTmpValue);
    dataJsonObj.Add("SysDate", strTmpValue);

    
    CSysInfo::GetRtcTime(strTmpValue);
    dataJsonObj.Add("RtcTime", strTmpValue);

    
    CSysInfo::GetRtcDate(strTmpValue);
    dataJsonObj.Add("RtcDate", strTmpValue);


    strRspData = rspJsonObj.ToString();
}

void CHttpCmdGetDateTime::ClearCmdLocalData()
{
    m_strTimeFormat.clear();
    m_strDateFormat.clear();
    m_strArgs.clear();
}

bool CHttpCmdGetDateTime::ParseParamDataToSave(const std::string &strReqMessage)
{
    neb::CJsonObject reqJsonObj(strReqMessage);
    neb::CJsonObject &dataJsonObj = reqJsonObj["Data"];

    // These Args are optional
    dataJsonObj.Get("TimeFormat", m_strTimeFormat);
    dataJsonObj.Get("DateFormat", m_strDateFormat);
    dataJsonObj.Get("Args", m_strArgs);

    return true;
}